Data, aesthetic mappings, geometric objects, statistical transformations, and positional adjustment form layers.
Create a blank canvas
Can assign a variable to a ggplot object
Data must be in a data frame
First argument is your data frame
size = sample(x=c(4, 3, 2, 1), size=nrow(df),
prob=c(.1, .2, .3, .4), replace=T)
group = sample(x = c("a", "b", "c", "d"), size=nrow(df),
prob=c(.1, .2, .3, .4), replace=T)
df = cbind(df, size=size, color=group)
ggplot(df, aes(x=x, y=y, size=size, color=group)) + geom_point()ggplot(df, aes(x=x, y=y, color=group)) +
geom_smooth() + geom_point()
ggplot(df, aes(x=x, y=y)) +
geom_smooth() + geom_point(aes(color=group))ggplot(df, aes(x=x, y=y)) +
geom_point() + geom_smooth()
ggplot(df, aes(x=x, y=y)) +
geom_point() + geom_smooth(method=lm) ggplot(df) + geom_bar(aes(x=group, fill=factor(size)))
ggplot(df) + geom_bar(aes(x=group, fill=factor(size)), position="dodge")ggplot(df) + geom_bar(aes(x=group, y=stat(prop), group=1))
ggplot(df) +
geom_bar(aes(x=group, y=stat(prop), group = 1)) +
scale_y_continuous(labels=scales::percent)df$yExp <- exp(df$y)
ggplot(df, aes(x=x, y=yExp)) +
geom_point()
ggplot(df, aes(x=x, y=yExp)) +
geom_point() + scale_y_log10()ggplot(df, aes(x=x, y=y)) + geom_point() +
coord_cartesian()
ggplot(df, aes(x=x, y=y)) + geom_point() +
coord_cartesian(xlim = c(4, 6))library(mapproj)
ggplot() +
geom_polygon(data=map_data("world"), aes(x=long, y=lat, group=group)) +
coord_map("orthographic", orientation=c(0, 0, 0))
ggplot() +
geom_polygon(data=map_data("world"), aes(x=long, y=lat, group=group)) +
coord_map("mercator", xlim=c(-180,180))Data, aesthetic mappings, geometric objects, statistical transformations, and positional adjustment form layers.
ggplot(df, aes(x=x, y=y, color=group)) + geom_point() +
labs(title="Random Data",
subtitle="Plotting some randomly generated data",
x="The x-axis",
y="The y-axis",
color="The groups")Three main components:
library(shiny)
ui <- fluidPage()
server <- function(input, output) {}
shinyApp(ui = ui, server = server)This code must go into a file named app.R or into an R markdown cell.
What to do with shiny app?
Can be embedded in R markdown
Host it on a website